class Solution {
    public void moveZeroes(int[] nums) {

        int left=0;
        int right=0;

        while(right<nums.length){
            if(nums[left]!=0){

                if(left==right){
                    right++;
                }
                left++;
            }else if(nums[right]!=0){
                int tmp=nums[left];
                nums[left]=nums[right];
                nums[right]=tmp;
                left++;
                right++;

            }else{
                right++;

            }
        }
    }
}


class Solution {
    public void duplicateZeros(int[] arr) {
        int size=arr.length;
        int left=0;
        int right=0;
        while(true){
            if(arr[left]==0){
                right+=2;
            }else{
                right++;
            }

            if(right>=size){
                break;
            }

            left++;

        }

        if(right!=size){
            right-=2;
            arr[right]=0;
            left--;
            right--;
        }else{
            right--;
        }




        while(left>=0){
            if(arr[left]==0){
                arr[right]=0;
                arr[--right]=0;


            }else{
                arr[right]=arr[left];

            }
            right--;
            left--;
        }


    }
}



class Solution {

    public boolean isHappy(int n) {
        int fast=n;
        int slow=n;

        do{
            fast=func(func(fast));
            slow=func(slow);

            if(fast==1||slow==1){
                return true;
            }


        }while(fast!=slow);

        if(fast!=1){

            return false;
        }else{
            return true;
        }




    }





    private int func(int cur){
        int sum=0;
        int n;
        while(cur!=0){
            n=cur%10;
            cur/=10;
            sum+=n*n;
        }

        return sum;

    }

}